package cn.fyl._02_xhr;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

public class Producer {

    public static void main(String[] args) throws Exception {
        // 创建生产者对象
        DefaultMQProducer producer = new DefaultMQProducer("xhr_producer_group");
        // 设置nameserver的地址
        producer.setNamesrvAddr("localhost:9876");
        // 启动
        producer.start();
        // 创建消息
        Message message = new Message("xhr", "hello", "我在佘豆传媒当代理".getBytes(StandardCharsets.UTF_8));
        // 发送消息
        producer.send(message, new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {
                System.out.println("消费消息成功");
            }

            @Override
            public void onException(Throwable throwable) {
                throwable.printStackTrace();
                System.out.println("消费消息失败");

            }
        });
        System.out.println("佘豆传媒一级代理商");
        // 关闭
        // producer.shutdown();

    }
}
